<template>
  <div>
    <div class="slot">
      <div class="top">
        <div class="return" @click="goback">
          <img src="@/assets/my/zuo.png" alt />
        </div>
        <span>佣金明细</span>
      </div>
    </div>
    <div class="main">
      <div class="main_top">
        <div class="center_left">
          共获得佣金：
          <span class="span1">￥</span>
          <span class="span2">{{allprice}}</span>
        </div>
        <div class="bj">
          <img src="@/assets/pblic/bj5.png" alt />
        </div>
      </div>
      <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
        <van-list
          :finished="finished"
          @load="onLoad"
          v-model="loading"
          finished-text="暂无数据了~"
          :immediate-check="false"
        >
          <div class="mian_ul">
            <div class="ul_li" v-for="item in list" :key="item.store_id">
              <div class="li_left">
                <img :src="item.avatar" alt />
                <div class="userinfo">
                  <div class="name">{{item.name}}</div>
                  <div class="time">{{item.add_time}}</div>
                </div>
              </div>
              <div class="li_right">
                ￥
                <span>{{item.amount}}</span>
              </div>
            </div>
          </div>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      allprice: 0,
      list: [],
      loading: false, //是否在上拉加载
      isLoading: false, //是否在刷新
      finished: false, //是否加载完成
      page: 1,
      total: 0,
      raw: 20,
      token:""
    };
  },
  mounted() {
    this.token = window.localStorage.getItem("token")
    this.onRefresh();
    var winHeight = document.documentElement.clientHeight; //视口大小
    document.getElementById("mian_ul").style.minHeight =
      winHeight - 82 + "px"; //调整上拉加载框高度
  },
  methods: {
    goback() {
      this.$router.back();
    },
    // 下拉刷新
    onRefresh() {
      this.page = 1;
      this.finished = false;
      this.getList();
    },
    //上拉加载
    onLoad() {
      // 异步更新数据
      console.log("加载");
      this.page++;
      axios
        .post("/index/user/Commi_details", this.$qs.stringify({
          token: this.token,
          page: this.page,
        }))
        .then((res) => {
          var list1 = res.data.data.data;
          this.total = res.data.data.total;
          this.list = [...this.list, ...list1];
          // 加载状态结束
          this.loading = false;
          // 数据全部加载完成
          if (this.list.length >= this.total) {
            this.finished = true;
          }
        });
    },
    getList() {
      axios
        .post("/index/user/Commi_details", this.$qs.stringify({
          token: this.token,
          page: this.page,
        }))
        .then((res) => {
          this.list = res.data.data.data;
          this.allprice = res.data.data.commission;
          this.total = res.data.data.total;
          this.isLoading = false;
          if (this.list.length >= this.total) {
            this.finished = true;
          }
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.slot {
  width: 100%;
  height: 44px;
  .top {
    width: 100%;
    height: 44px;
    display: flex;display: -webkit-flex;
    justify-content: center;
    align-items: center;
    background: white;
    position: fixed;
    top: 0;
    left: 0;
    .return {
      width: 38px;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      display: flex;display: -webkit-flex;
      justify-content: center;
      align-items: center;
      img {
        width: 8px;
        height: 15px;
      }
    }
    span {
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #000000;
      line-height: 44px;
    }
  }
}
.main {
  width: 345px;
  margin: auto;
  margin-top: 10px;
  .main_top {
    width: 345px;
    height: 65px;
    background: linear-gradient(90deg, #ffe200 0%, #ffc700 100%);
    box-shadow: 0px 15px 30px 0px rgba(255, 199, 0, 0.4);
    border-radius: 10px;
    display: flex;display: -webkit-flex;
    align-items: center;
    position: relative;
    .center_left {
      margin-left: 15px;
      font-size: 12px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #222222;
      line-height: 12px;
      .span1 {
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 16px;
      }
      .span2 {
        font-size: 23px;
        font-weight: bold;
        font-family: PingFang-SC-Bold;
        color: #000000;
        line-height: 23px;
      }
    }
    .bj {
      width: 68px;
      height: 51px;
      position: absolute;
      right: 19px;
      bottom: 0;
      img {
        width: 100%;
      }
    }
  }
  .mian_ul {
    width: 100%;
    .ul_li {
      width: 100%;
      height: 75px;
      display: flex;display: -webkit-flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #f8f8f8;
      .li_left {
        display: flex;display: -webkit-flex;
        align-items: center;
        img {
          width: 35px;
          height: 35px;
          margin-right: 10px;
          border-radius: 50%;
        }
        .userinfo {
          .name {
            font-size: 16px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #222222;
            line-height: 16px;
          }
          .time {
            font-size: 12px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #bbbbbb;
            line-height: 12px;
            margin-top: 10px;
          }
        }
      }
      .li_right {
        font-size: 13px;
        font-family: PingFang SC;
        font-weight: 500;
        color: #ff511e;
        line-height: 13px;
        span {
          font-size: 17px;
          font-family: PingFang-SC-Heavy;
          font-weight: bold;
        }
      }
    }
  }
}
</style>